package com.cyl.manager.act.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;


import com.cyl.manager.act.domain.entity.FhFamilies;
import com.cyl.manager.act.domain.convert.FhFamiliesConvert;
import com.cyl.manager.act.domain.query.FhFamiliesQuery;
import com.cyl.manager.act.domain.vo.FhFamiliesVO;
import com.cyl.manager.act.service.FhFamiliesService;

import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 鱼类科属Controller
 *
 * @author zcc
 * @date 2025-06-07
 */
@Api(description = "鱼类科属接口列表")
@RestController
@RequestMapping("/act/fhFamilies")
public class FhFamiliesController extends BaseController {
    @Autowired
    private FhFamiliesService service;
    @Autowired
    private FhFamiliesConvert convert;

    @ApiOperation("查询鱼类科属列表")
    @PreAuthorize("@ss.hasPermi('act:fhFamilies:list')")
    @PostMapping("/list")
    public ResponseEntity<Page<FhFamilies>> list(@RequestBody FhFamiliesQuery query, Pageable page) {
        List<FhFamilies> list = service.selectList(query, page);
        return ResponseEntity.ok(new PageImpl<>(list, page, ((com.github.pagehelper.Page) list).getTotal()));
    }

    @ApiOperation("导出鱼类科属列表")
    @PreAuthorize("@ss.hasPermi('act:fhFamilies:export')")
    @Log(title = "鱼类科属", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ResponseEntity<String> export(FhFamiliesQuery query) {
        List<FhFamilies> list = service.selectList(query, null);
        ExcelUtil<FhFamiliesVO> util = new ExcelUtil<>(FhFamiliesVO.class);
        return ResponseEntity.ok(util.writeExcel(convert.dos2vos(list), "鱼类科属数据"));
    }

    @ApiOperation("获取鱼类科属详细信息")
    @PreAuthorize("@ss.hasPermi('act:fhFamilies:query')")
    @GetMapping(value = "/{id}")
    public ResponseEntity<FhFamilies> getInfo(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(service.selectById(id));
    }

    @ApiOperation("新增鱼类科属")
    @PreAuthorize("@ss.hasPermi('act:fhFamilies:add')")
    @Log(title = "鱼类科属", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody FhFamilies fhFamilies) {
        return ResponseEntity.ok(service.insert(fhFamilies));
    }

    @ApiOperation("修改鱼类科属")
    @PreAuthorize("@ss.hasPermi('act:fhFamilies:edit')")
    @Log(title = "鱼类科属", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Integer> edit(@RequestBody FhFamilies fhFamilies) {
        return ResponseEntity.ok(service.update(fhFamilies));
    }

    @ApiOperation("删除鱼类科属")
    @PreAuthorize("@ss.hasPermi('act:fhFamilies:remove')")
    @Log(title = "鱼类科属", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResponseEntity<Integer> remove(@PathVariable Long[] ids) {
        return ResponseEntity.ok(service.deleteByIds(ids));
    }

    @ApiOperation("查询鱼类科属列表")
    @GetMapping("/fhList")
    public ResponseEntity<List<FhFamilies>> fhList() {
        List<FhFamilies> list = service.fhList();
        return ResponseEntity.ok(list);
    }
}
